#include <iostream>
#include <new>
#include <vector>
#include <exception>
#include <cmath>
#include <limits>

 
#ifndef MATRIX_H
#define MATRIX_H
 
template <typename T>
class MyMatrix
{
 private:
	int row, col;
	T ** matrix;
 public :
	MyMatrix();  // default constructor
	MyMatrix(int ro, int co);  // constructor #1
	MyMatrix(int ro, int co, T ** f);  // constructor #2
	~MyMatrix()
	  { for (int n = 0; n < row; n++)
	      delete[] matrix[n];
	    delete[] matrix; };  // destructor
	MyMatrix(const MyMatrix & ma);  // copy constructor
	template <typename T> 
	friend MyMatrix<T> operator*(const T k, const MyMatrix<T> & ma);  
};


template <typename T>
MyMatrix<T>::MyMatrix()
{
	row = 0;
	col = 0;
	matrix = nullptr;
}

template <typename T>
MyMatrix<T>::MyMatrix(int ro, int co)
{
	row = ro;
	col = co;
	matrix = new T*[row];
	for (int n = 0; n < row; n++) matrix[n] = new T[col];
	for (int i = 0; i < row; i++)
		for (int j = 0; j < col; j++)
			matrix[i][j] = 0;
}

template <typename T>
MyMatrix<T>::MyMatrix(int ro, int co, T ** f)
{
	row = ro;
	col = co;
	matrix = new T*[row];
	for (int n = 0; n < row; n++) matrix[n] = new T[col];
	for (int i = 0; i < row; i++)
		for (int j = 0; j < col; j++)
			matrix[i][j] = f[i][j];
}

template <typename T>
MyMatrix<T>::MyMatrix(const MyMatrix & ma)
{
	row = ma.row;
	col = ma.col;
	matrix = new T*[row];
	for (int n = 0; n < row; n++) matrix[n] = new T[col];
	for (int i = 0; i < row; i++)
		for (int j = 0; j < col; j++)
			matrix[i][j] = ma.matrix[i][j];
}

template <typename T>
MyMatrix<T> operator*(const T k, const MyMatrix<T> & ma)
{
	MyMatrix<T> result(ma.row, ma.col);
	for (int i = 0; i < ma.row; i++)
		for (int j = 0; j < ma.col; j++)
			result.matrix[i][j] = k*ma.matrix[i][j];
	return result;
}
